import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  // 测试
  {
    path: '/Acheshi',
    component: Layout,
    redirect: '/Acheshi/usercenter',
    name: 'Acheshi',
    meta: { title: '测试', icon: 'el-icon-folder' },
    alwaysShow: true,
    children: [
      {
        path: 'usercenter1',
        name: 'AcheshiUsercenter1',
        component: () => import('@/views/Acheshi/usercenter1'),
        meta: { title: '测试1', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter2',
        name: 'AcheshiUsercenter2',
        component: () => import('@/views/Acheshi/usercenter2'),
        meta: { title: '测试2', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter3',
        name: 'AcheshiUsercenter3',
        component: () => import('@/views/Acheshi/usercenter3'),
        meta: { title: '测试3', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter4',
        name: 'AcheshiUsercenter4',
        component: () => import('@/views/Acheshi/usercenter4'),
        meta: { title: '测试4', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter5',
        name: 'AcheshiUsercenter5',
        component: () => import('@/views/Acheshi/usercenter5'),
        meta: { title: '测试5', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter6',
        name: 'AcheshiUsercenter6',
        component: () => import('@/views/Acheshi/usercenter6'),
        meta: { title: '测试6', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter7',
        name: 'AcheshiUsercenter7',
        component: () => import('@/views/Acheshi/usercenter7'),
        meta: { title: '测试7', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter8',
        name: 'AcheshiUsercenter8',
        component: () => import('@/views/Acheshi/usercenter8'),
        meta: { title: '测试8', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter9',
        name: 'AcheshiUsercenter9',
        component: () => import('@/views/Acheshi/usercenter9'),
        meta: { title: '测试9', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter10',
        name: 'AcheshiUsercenter10',
        component: () => import('@/views/Acheshi/usercenter10'),
        meta: { title: '测试10', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter11',
        name: 'AcheshiUsercenter11',
        component: () => import('@/views/Acheshi/usercenter11'),
        meta: { title: '测试11', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter12',
        name: 'AcheshiUsercenter12',
        component: () => import('@/views/Acheshi/usercenter12'),
        meta: { title: '测试12', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter13',
        name: 'AcheshiUsercenter13',
        component: () => import('@/views/Acheshi/usercenter13'),
        meta: { title: '测试13', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter14',
        name: 'AcheshiUsercenter14',
        component: () => import('@/views/Acheshi/usercenter14'),
        meta: { title: '测试14', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter15',
        name: 'AcheshiUsercenter15',
        component: () => import('@/views/Acheshi/usercenter15'),
        meta: { title: '测试15', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter16',
        name: 'AcheshiUsercenter16',
        component: () => import('@/views/Acheshi/usercenter16'),
        meta: { title: '测试16', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter17',
        name: 'AcheshiUsercenter17',
        component: () => import('@/views/Acheshi/usercenter17'),
        meta: { title: '测试17', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter18',
        name: 'AcheshiUsercenter18',
        component: () => import('@/views/Acheshi/usercenter18'),
        meta: { title: '测试18', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter19',
        name: 'AcheshiUsercenter19',
        component: () => import('@/views/Acheshi/usercenter19'),
        meta: { title: '测试19', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter20',
        name: 'AcheshiUsercenter20',
        component: () => import('@/views/Acheshi/usercenter20'),
        meta: { title: '测试20', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter21',
        name: 'AcheshiUsercenter21',
        component: () => import('@/views/Acheshi/usercenter21'),
        meta: { title: '测试21', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter22',
        name: 'AcheshiUsercenter22',
        component: () => import('@/views/Acheshi/usercenter22'),
        meta: { title: '测试22', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter23',
        name: 'AcheshiUsercenter23',
        component: () => import('@/views/Acheshi/usercenter23'),
        meta: { title: '测试23', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter24',
        name: 'AcheshiUsercenter24',
        component: () => import('@/views/Acheshi/usercenter24'),
        meta: { title: '测试24', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter25',
        name: 'AcheshiUsercenter25',
        component: () => import('@/views/Acheshi/usercenter25'),
        meta: { title: '测试25', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter26',
        name: 'AcheshiUsercenter26',
        component: () => import('@/views/Acheshi/usercenter26'),
        meta: { title: '测试26', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter27',
        name: 'AcheshiUsercenter27',
        component: () => import('@/views/Acheshi/usercenter27'),
        meta: { title: '测试27', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter28',
        name: 'AcheshiUsercenter28',
        component: () => import('@/views/Acheshi/usercenter28'),
        meta: { title: '测试28', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter29',
        name: 'AcheshiUsercenter29',
        component: () => import('@/views/Acheshi/usercenter29'),
        meta: { title: '测试29', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter30',
        name: 'AcheshiUsercenter30',
        component: () => import('@/views/Acheshi/usercenter30'),
        meta: { title: '测试30', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter31',
        name: 'AcheshiUsercenter31',
        component: () => import('@/views/Acheshi/usercenter31'),
        meta: { title: '测试31', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter32',
        name: 'AcheshiUsercenter32',
        component: () => import('@/views/Acheshi/usercenter32'),
        meta: { title: '测试32', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter33',
        name: 'AcheshiUsercenter33',
        component: () => import('@/views/Acheshi/usercenter33'),
        meta: { title: '测试33', icon: 'el-icon-tickets' }
      },
      {
        path: 'usercenter34',
        name: 'AcheshiUsercenter34',
        component: () => import('@/views/Acheshi/usercenter34'),
        meta: { title: '测试34', icon: 'el-icon-tickets' }
      }
    ]
  },
  // 权限管理
  {
    path: '/authority',
    component: Layout,
    redirect: '/authority/account',
    name: 'authority',
    meta: { title: '权限管理', icon: 'el-icon-folder' },
    children: [
      {
        path: 'account',
        name: 'AuthorityAccount',
        component: () => import('@/views/authority/account'),
        meta: { title: '账号管理', icon: 'el-icon-tickets' }
      },
      {
        path: 'character',
        name: 'AuthorityCharacter',
        component: () => import('@/views/authority/character'),
        meta: { title: '角色管理', icon: 'img' }
      },
      {
        path: 'resource',
        name: 'AuthorityResource',
        component: () => import('@/views/authority/resource'),
        meta: { title: '资源管理', icon: 'img' }
      }
    ]
  },
  // 商品管理
  {
    path: '/product',
    component: Layout,
    redirect: '/product/list',
    name: 'product',
    meta: { title: '商品管理', icon: 'el-icon-burger' },
    children: [
      {
        path: 'list',
        name: 'ProductList',
        component: () => import('@/views/product/list'),
        meta: { title: '商品列表', icon: 'el-icon-shopping-bag-2' }
      },
      {
        path: 'newshow',
        hidden: true,
        name: 'productNewshow',
        component: () => import('@/views/product/newShow'),
        meta: { title: '新增商品', icon: 'el-icon-shopping-bag-2', activeMenu: '/product/list' }
      },
      {
        path: 'copyreader',
        hidden: true,
        name: 'productCopyreader',
        component: () => import('@/views/product/copyreader'),
        meta: { title: '编辑商品', icon: 'el-icon-shopping-bag-2', activeMenu: '/product/list' }
      },
      {
        path: 'classify',
        name: 'ProductClassify',
        component: () => import('@/views/product/classify'),
        meta: { title: '商品分类', icon: 'el-icon-menu' }
      },
      {
        path: 'judge',
        name: 'ProductJudge',
        component: () => import('@/views/product/judge'),
        meta: { title: '品牌管理', icon: 'el-icon-present' }
      }
    ]
  },

  // 订单管理
  {
    path: '/order',
    component: Layout,
    redirect: '/order/reference',
    name: 'order',
    meta: { title: '订单管理', icon: 'el-icon-tickets' },
    children: [
      {
        path: 'reference',
        name: 'OrderReference',
        component: () => import('@/views/order/reference'),
        meta: { title: '订单列表', icon: 'el-icon-folder-checked' }
      },
      {
        path: 'OrderAmount',
        hidden: true,
        name: 'OrderAmount',
        component: () => import('@/views/order/OrderAmount'),
        meta: { title: '订单详情', icon: 'el-icon-tickets', activeMenu: '/order/reference' }
      },
      {
        path: 'unwinding',
        name: 'OrderUnwinding',
        component: () => import('@/views/order/unwinding'),
        meta: { title: '退单列表', icon: 'el-icon-folder-delete' }
      },
      {
        path: 'Singledetails',
        hidden: true,
        name: 'Singledetails',
        component: () => import('@/views/order/Singledetails'),
        meta: { title: '退单详情', icon: 'el-icon-tickets', activeMenu: '/order/unwinding' }
      },
      {
        path: 'location',
        name: 'OrderLocation',
        component: () => import('@/views/order/location'),
        meta: { title: '地址管理', icon: 'el-icon-school' }
      }
    ]
  },
  // 注册用户管理
  {
    path: '/registered',
    component: Layout,
    redirect: '/registered/usercenter',
    name: 'Registered',
    meta: { title: '注册用户管理', icon: 'el-icon-folder' },
    alwaysShow: true,
    children: [
      {
        path: 'usercenter',
        name: 'RegisteredUsercenter',
        component: () => import('@/views/registered/usercenter'),
        meta: { title: '用户列表', icon: 'el-icon-tickets' }
      }
    ]
  },
  // 营销管理
  {
    path: '/campaign',
    component: Layout,
    redirect: '/campaign/table',
    name: 'campaign',
    meta: { title: '营销管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'timeactivities',
        name: 'CampaignTimeactivities',
        component: () => import('@/views/campaign/advertising'),
        meta: { title: '限时活动', icon: 'table' }
      },
      {
        path: 'advertising',
        name: 'CampaignAdvertising',
        component: () => import('@/views/campaign/timeactivities'),
        meta: { title: '广告列表', icon: 'tree' }
      }
    ]
  },
  // 内容管理
  {
    path: '/Management',
    component: Layout,
    redirect: '/Management/article',
    name: 'Management',
    meta: { title: '内容管理', icon: 'el-icon-folder' },
    children: [
      // newly
      {
        path: 'newly',
        hidden: true,
        name: 'newly',
        component: () => import('@/views/management/newly'),
        meta: { title: '新增文章', icon: 'el-icon-tickets', activeMenu: '/Management/article' }
      },
      {
        path: 'article',
        name: 'article',
        component: () => import('@/views/management/article'),
        meta: { title: '文章列表', icon: 'el-icon-tickets' }
      },
      {
        path: 'fodder',
        name: 'fodder',
        component: () => import('@/views/management/fodder'),
        meta: { title: '素材列表', icon: 'img' }
      },
      {
        path: 'redact',
        name: 'redact',
        hidden: true,
        component: () => import('@/views/management/redact'),
        meta: {
          title: '编辑文章', icon: 'img', activeMenu: 'Management/article'
        }
      }
    ]
  },
  // 个人中心
  {
    path: '/researchcenter',
    component: Layout,
    redirect: '/researchcenter/technical',
    name: 'researchcenter',
    meta: { title: '个人中心', icon: 'el-icon-folder' },
    children: [
      {
        path: 'technical',
        name: 'researchcenterTechnical',
        component: () => import('@/views/researchcenter/technical'),
        meta: { title: '个人主页', icon: 'el-icon-tickets' }
      },
      {
        path: 'default',
        name: 'researchcenterDefault',
        component: () => import('@/views/researchcenter/default'),
        meta: { title: '个人设置', icon: 'img' }
      }
    ]
  },
  // 测试
  {
    path: '/testreport',
    component: Layout,
    redirect: '/testreport/soldier',
    name: 'testreport',
    alwaysShow: true,
    meta: { title: '测试2102', icon: 'el-icon-folder' },
    children: [
      {
        path: 'soldier',
        name: 'TestreportSoldier',
        component: () => import('@/views/testreport/soldier'),
        meta: { title: '测试设置', icon: 'el-icon-tickets' }
      }
    ]
  },

  // {
  //   path: '/form',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Form',
  //       component: () => import('@/views/form/index'),
  //       meta: { title: 'Form', icon: 'form' }
  //     }
  //   ]
  // },

  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: 'Nested',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       path: 'menu1',
  //       component: () => import('@/views/nested/menu1/index'), // Parent router-view
  //       name: 'Menu1',
  //       meta: { title: 'Menu1' },
  //       children: [
  //         {
  //           path: 'menu1-1',
  //           component: () => import('@/views/nested/menu1/menu1-1'),
  //           name: 'Menu1-1',
  //           meta: { title: 'Menu1-1' }
  //         },
  //         {
  //           path: 'menu1-2',
  //           component: () => import('@/views/nested/menu1/menu1-2'),
  //           name: 'Menu1-2',
  //           meta: { title: 'Menu1-2' },
  //           children: [
  //             {
  //               path: 'menu1-2-1',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  //               name: 'Menu1-2-1',
  //               meta: { title: 'Menu1-2-1' }
  //             },
  //             {
  //               path: 'menu1-2-2',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  //               name: 'Menu1-2-2',
  //               meta: { title: 'Menu1-2-2' }
  //             }
  //           ]
  //         },
  //         {
  //           path: 'menu1-3',
  //           component: () => import('@/views/nested/menu1/menu1-3'),
  //           name: 'Menu1-3',
  //           meta: { title: 'Menu1-3' }
  //         }
  //       ]
  //     },
  //     {
  //       path: 'menu2',
  //       component: () => import('@/views/nested/menu2/index'),
  //       name: 'Menu2',
  //       meta: { title: 'menu2' }
  //     }
  //   ]
  // },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
